<template>
  <div>
    <div class="headerabs" v-show="showaAbs">
      <router-link to="/">
        <span class="iconfont">&#xe625;</span>
      </router-link>
    </div>
    <div class="headerfix" v-show="!showaAbs" :style="opacityStyle">
      <router-link to="/">
        <span class="iconfont">&#xe625;</span>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      showaAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      // console.log(document.documentElement.scrollTop)
      const topHeight = document.documentElement.scrollTop
      if (topHeight > 60) {
        let opacity = topHeight / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {
          opacity: opacity
        }
        this.showaAbs = false
      } else {
        this.showaAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import "~@/assets/style/varible.styl"
.headerabs
  position absolute
  top .2rem
  left .2rem
  width .8rem
  height .8rem
  border-radius 50%
  background rgba(0,0,0,.8)
  color $color-white
  text-align center
  line-height .3rem
  a
    font-size .6rem
    color $color-white
.headerfix
  position fixed
  top 0
  left 0
  background $color-blue
  width 100%
  height .8rem
  font-size .28rem
  color $color-white
  line-height .8rem
  text-align center
  a
    position absolute
    top 0
    left .2rem
    font-size .28rem
    color $color-white
</style>
